package com.nutricia.core.service.convertor;

import com.nutricia.common.dal.persistant.SystemPermission;
import com.nutricia.core.model.domain.SystemPermissionDO;
import org.apache.commons.collections.CollectionUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 系统权限对象转换器
 *
 * @author: huangsheng
 * @date: 2017/10/20
 */
public class SystemPermissionServiceConvertor {

   /**
    * 将 SystemPermission 转换为 SystemPermissionDO
    *
    * @author: huangsheng
    * @date: 2017/10/24 上午10:48
    */
    public static SystemPermissionDO convertToSystemPermissionDO(final SystemPermission systemPermission) {
        if (null == systemPermission) {
            return null;
        }
        SystemPermissionDO systemPermissionDO = new SystemPermissionDO();
        systemPermissionDO.setId(systemPermission.getId());
        systemPermissionDO.setMenuId(systemPermission.getPermissionCode());
        systemPermissionDO.setPermissionName(systemPermission.getPermissionName());
        systemPermissionDO.setPermissionCode(systemPermission.getPermissionCode());
        return systemPermissionDO;
    }

    /**
     * 将SystemUsers转换为SystemUserDOs
     *
     * @author: huangsheng
     * @date: 2017/10/20 下午2:00
     */
    public static List<SystemPermissionDO> convertToSystemPermissionDOs(final List<SystemPermission> systemPermissions) {
        List<SystemPermissionDO> systemPermissionDOS = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(systemPermissions)) {
            systemPermissions.forEach(systemPermission -> {
                systemPermissionDOS.add(SystemPermissionServiceConvertor.convertToSystemPermissionDO(systemPermission));
            });
            return systemPermissionDOS;
        }
        return Collections.emptyList();
    }

}
